package com.ruoyi.insurance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.insurance.domain.ClaimRecord;
import com.ruoyi.insurance.service.IClaimRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 索赔记录Controller
 * 
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/insurance/record")
public class ClaimRecordController extends BaseController
{
    @Autowired
    private IClaimRecordService claimRecordService;

    /**
     * 查询索赔记录列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClaimRecord claimRecord)
    {
        startPage();
        List<ClaimRecord> list = claimRecordService.selectClaimRecordList(claimRecord);
        return getDataTable(list);
    }

    /**
     * 导出索赔记录列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:record:export')")
    @Log(title = "索赔记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClaimRecord claimRecord)
    {
        List<ClaimRecord> list = claimRecordService.selectClaimRecordList(claimRecord);
        ExcelUtil<ClaimRecord> util = new ExcelUtil<ClaimRecord>(ClaimRecord.class);
        util.exportExcel(response, list, "索赔记录数据");
    }

    /**
     * 获取索赔记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:record:query')")
    @GetMapping(value = "/{claimId}")
    public AjaxResult getInfo(@PathVariable("claimId") Long claimId)
    {
        return success(claimRecordService.selectClaimRecordByClaimId(claimId));
    }

    /**
     * 新增索赔记录
     */
    @PreAuthorize("@ss.hasPermi('insurance:record:add')")
    @Log(title = "索赔记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClaimRecord claimRecord)
    {
        return toAjax(claimRecordService.insertClaimRecord(claimRecord));
    }

    /**
     * 修改索赔记录
     */
    @PreAuthorize("@ss.hasPermi('insurance:record:edit')")
    @Log(title = "索赔记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClaimRecord claimRecord)
    {
        return toAjax(claimRecordService.updateClaimRecord(claimRecord));
    }

    /**
     * 删除索赔记录
     */
    @PreAuthorize("@ss.hasPermi('insurance:record:remove')")
    @Log(title = "索赔记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{claimIds}")
    public AjaxResult remove(@PathVariable Long[] claimIds)
    {
        return toAjax(claimRecordService.deleteClaimRecordByClaimIds(claimIds));
    }
}
